/*
* created by kaweepapkongkittisan
*
*/


package com.tuinui.trade;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DownloadAndUpdate {
	final public static Logger _log = LoggerFactory.getLogger(DownloadAndUpdate.class);

	public static void main(String[] args)throws Exception{
		String setUrl = "http://marketdata.set.or.th/mkt/aomstocklistresult.do?tradingMethod=aomstocklistresult.do&market=SET&language=th&country=TH";
		String maiUrl = "http://marketdata.set.or.th/mkt/aomstocklistresult.do?tradingMethod=aomstocklistresult.do&market=mai&language=th&country=TH";
		IStockPriceDownloader downloader = new StockPriceDownloaderSetCoThImpl();
		_log.info("Starting program.");
		downloader.setSource(new String[]{setUrl, maiUrl});
		_log.info("Downloading stock price ...");
		downloader.downloadSource();
		List<StockTradeDailyEntry> tradeInfo = downloader.extractStockPrice();
		_log.info("Downloaded stock price.");
		
		for (StockTradeDailyEntry e: tradeInfo){
			_log.debug("------------------------");
			_log.debug("Symbol: " + e.getSymbol());
			_log.debug("Flag: " + e.getFlag());
			_log.debug("Open: " + e.getOpen());
			_log.debug("High: " + e.getHigh());
			_log.debug("Low: " + e.getLow());
			_log.debug("Last: " + e.getLast());
			_log.debug("Change: " + e.getChange());
			_log.debug("Percent Change: " + e.getPercentChange());
			_log.debug("Offer: " + e.getOffer());
			_log.debug("Bid: " + e.getBid());
			_log.debug("Volume Trade: " + e.getVolumeTrade());
			_log.debug("Value Trade: " + e.getValueTrade());
			_log.debug("------------------------");

		}
		_log.info("Updating stock price to excel file ...");
		//String excelFile = "/Users/kaweepapkongkittisan/Documents/workspace/stock-trade/src/test/resources/port2011.xlsx";
		String excelFile = args[0];
		IStockPriceUpdater updator = new StockPriceUpdaterExcelPOIImpl();
		updator.setSource(excelFile);
		updator.updatePrice(tradeInfo);
		_log.info("Updated stock price to excel file ...");
		
		_log.info("End program.");
	}
}
